<?php
$id = $_GET['id'];
if(@$_POST['btnCancel']) btnCancel($page);
if($id == '0'){ //create
	$name = 'btnSubmit';
	$display = 'Thêm mới';
	
	//hidden field user_create
	$form->getProperties(NULL, 'user_create', 2, NULL, $user, 20);
	$user_login = $form->DisplayProperties();
	//hidden field date_create
	$form->getProperties(NULL, 'date_create', 2, NULL, date('Y-m-d H:i:s'), 20);
	$date_create = $form->DisplayProperties();
	
	$ma = "input_medium";
	
	$type = 1; //loại sql create $type = 1;
} else {  //update
	$name = 'btnSubmit';
	$display = 'Cập nhật';
	$qr_detail = mysql_query("SELECT * FROM {$page} WHERE id='{$id}'");
	$detail = mysql_fetch_array($qr_detail);
	mysql_free_result($qr_detail);
	
	$ma = "input_medium' readonly='readonly";
	
	//hidden field user_update
	$form->getProperties(NULL, 'user_update', 2, NULL, $user, 20);
	$user_login = $form->DisplayProperties();
	$form->getProperties(NULL, 'date_update', 2, NULL, date('Y-m-d H:i:s'), 20);
	$date_create = $form->DisplayProperties();
	
	$type = 2; //loại sql update $type = 2;
}

if(!empty($_POST)){
	$table = str_replace('_ac','',$p);
	$field = array_keys($_POST);
	$value = array_values($_POST);
	$sql->get_sql($type,$table,$field,$value,$id);
	$check = $sql->executable();
	
	if($type==1) include "library/phpmailer/send.php";
	
	if($check == 1) header("location:administrator.php?p=".$page);
	else echo "<p class='error'>{$check}</p>";
}

/*
********************************************************************
* $form->getProperties($displayname, $name, $type, $cssclass, $value = NULL, $length = NULL, $orther = NULL);
* $form->DisplayProperties();
* $type = 1 // text
* $type = 2 // hidden
* $type = 3 // textarea
* $type = 4 // checkbox
* $type = 41// checkbox group
* $type = 5 // radio
* $type = 6 // select
* $type = 7 // button
* $type = 8 // submit
* $type = 9 // DeQuy
********************************************************************
***********
* NOT USED
* other, lang, delete
*/
// form
echo "
<form action='' method='post' name='form1'>
<table width='620' border='0' cellspacing='0' cellpadding='5'>
";
//date create
echo $date_create;
//user login
echo $user_login;
//khoa hoc
$level = '';
$style1 = '';
$style2 = '';
$str_query = array("SELECT id, ten FROM khoahoc ", " WHERE `delete`=0 ", " ORDER BY `id` ");
$form->getProperties($level, $style1, 9, $style2, $str_query);
$values = $form->DisplayProperties();
if(@$_POST['khoahoc_id']) $check = $_POST['khoahoc_id']; else $check = $detail['khoahoc_id'];
$form->getProperties('Khóa học', 'khoahoc_id', 6, 'input_medium', $values, $check);
echo $form->DisplayProperties();
//id
if(@$_POST['id']) $value = $_POST['id']; else $value = $detail['id'];
$form->getProperties('Mã lớp', 'id', 1, $ma, $value, 10);
echo $form->DisplayProperties();
//tenlop
if(@$_POST['ten']) $value = $_POST['ten']; else $value = $detail['ten'];
$form->getProperties('Tên lớp', 'ten', 1, 'input_medium', $value, 50);
echo $form->DisplayProperties();
//ngaykg
if(@$_POST['date_1']) $value = $_POST['date_1'];
else if($detail['date_1'] != '') $value = date('d/m/Y', strtotime($detail['date_1']));
else $value = '';
$form->getProperties('Ngày KG', 'date_1', 1, 'input_large', $value, 10);
echo $form->DisplayProperties();
//soluong
if(@$_POST['soluong']) $value = $_POST['soluong']; else $value = $detail['soluong'];
$form->getProperties('SL học viên', 'soluong', 1, 'input_medium', $value, 2);
echo $form->DisplayProperties();
//hocphi
if(@$_POST['hocphi']) $value = $_POST['hocphi']; else $value = $detail['hocphi'];
$form->getProperties('Học phí lớp này', 'hocphi', 1, 'input_medium', $value, 10);
echo $form->DisplayProperties();
//notes
if(@$_POST['notes']) $value = $_POST['notes']; else $value = $detail['notes'];
$form->getProperties('Ghi chú', 'notes', 3, 'textarea', $value, 1);
echo $form->DisplayProperties();

echo "
<tr style='background:#b0b0b0'>
    <th align='right'>&nbsp;</th> 
    <td><input type='submit' name='{$name}' value='{$display}' id='{$name}' class='button' />
	<input type='button' name='btnCancel' value='Hủy' class='button' onClick='window.location.href=\"administrator.php?p={$page}\"'>
	</td>
</tr>
</table>
</form>
<br />
";
?>